package com.auxiliary;

import com.auxiliary.TimeSequence;

import java.util.ArrayList;


public class SignalIndexCalculator
{
   /// <summary>
    /// 计算综合景情指数
   /// </summary>
    /// <param name="signalTS">输入指标的灯值序列</param>
   /// <param name="weightArrayList">指标权重序列</param>
   /// <returns></returns>
    private TimeSequence CalculateSignalIndex (ArrayList<TimeSequence> signalTS, ArrayList<Double> weightArrayList)
    {
        
        TimeSequence signalIndex = new TimeSequence();
//        int count = signalTS.size();
        ArrayList<Double> a = new ArrayList<>();
        for (int i = 0; i < signalTS.get(0).getValueList().size();i++ )
        {
            Double d = 0.0;
            for (int j = 0; j < signalTS.size(); j++)
            {

                d += signalTS.get(j).getValueList().get(i) * weightArrayList.get(j);
            }
            d = d * (10/signalTS.size()); //从0-10区间换到0-100区间
            a.add(d);
//            signalIndex.ChangeValue(signalTS.get(0).getDateList().get(i), d);
        }
        signalIndex.setValueList(a);

        return signalIndex;
    }
    /// <summary>
    /// 计算综合景情指数的数值
    /// </summary>
    /// <param name="signalTS">用于合成综合景情指数的指标对应的灯值</param>
    /// <param name="weightArrayList">合成综合景情指数的TimeSequence ArrayList对应的权重列表，需要与TimeSequence一一对应，默认权重为等权重
    /// 权重的和需为1</param>
    /// <returns></returns>
    public TimeSequence Calculate(ArrayList<TimeSequence> signalTS, ArrayList<Double> weightArrayList)
    {
        if (signalTS == null || weightArrayList == null) return null;
        if (signalTS.get(0) == null) return null;
        return CalculateSignalIndex(signalTS, weightArrayList);
    }
    /// <summary>
    /// 计算综合景情指数的数值，采用默认等权重
    /// </summary>
    /// <param name="signalTS">用于合成综合景情指数的指标对应的灯值</param>
    /// <returns></returns>
    public TimeSequence Calculate(ArrayList<TimeSequence> signalTS)
    {
        if (signalTS == null ) return null;
        if (signalTS.get(0) == null) return null;
        ArrayList<Double> weightArrayList=new ArrayList<Double> ();
        for (int i = 0; i < signalTS.size(); i++)
        {
            Double temp = 1.0 / signalTS.size();
            weightArrayList.add(temp);
        }
        return CalculateSignalIndex(signalTS, weightArrayList);
    }            

}
